#include "SimpleLogging.h"
#include <string>

namespace SLOG {

// set default log level
static LogLevel currLogLevel = DEBUG_LEVEL;

// Level functions
LogLevel GetCurrLevel() { return currLogLevel; }
void SetInfoLevel() { currLogLevel = INFO_LEVEL; }; 
void SetErrorLevel() { currLogLevel = ERROR_LEVEL; }; 
void SetDebugLevel() { currLogLevel = DEBUG_LEVEL; }; 

// MsgPrinter -------------------------------------------------------------------
//

MsgPrinter::MsgPrinter(const char* filename, int lineNo, LogLevel level) {
	logStream_ << "[";
	switch(level) {
		case SLOG::INFO_LEVEL:
			logStream_ << "INFO_";
			break;
		case SLOG::ERROR_LEVEL:
			logStream_ << "ERROR";
			break;
		case SLOG::DEBUG_LEVEL:
			logStream_ << "DEBUG";
			break;
	}
	logStream_ << ":";

	// print filename
	std::string filenameStr(filename);
	size_t found = filenameStr.rfind("/");
	if (found != std::string::npos && found +1 < filenameStr.size()) {
		filenameStr = filenameStr.substr(found + 1);
	}

	logStream_ << filenameStr << ":" << lineNo << "] ";

	// original way
	//logStream_ << filename << ":" << lineNo << "] ";
}

MsgPrinter::~MsgPrinter() {
	logStream_ << endl;
	cerr << logStream_.str();
	//cerr << "destructed" << endl;
}

// MsgPrinter -------------------------------------------------------------------

}
